I - First words 
Ia - So, what things you could've done that makes you want to code? 
---- 1. Staring in awe of a masterpiece from one of the better AVS artists, then having a brain overload after looking at the coding involved. 
---- 2. Reviews of your presets said in one part, "Code!" 
---- 3. You just want to. 
Ib - Hopefully, you read the AVS FAQ at the main AVS forum first. If you don't... 
Ic - This part is useless, dontya think? 

----------------- 
II - Basic Coding 
----------------- 

IIa - Variables! 
--------Yes, there are many variables - Despite the fact that you can see as much as 100 variables in a single preset, but guess what, most of them aren't even something that come with AVS! More than half of them would be custom variables. That's something you don't need to know if you're just starting coding. 
--------So, what are the actual variables? 
-D, for distance 
-R, for rotation 
-X, for... X axis 
-Y, for Y axis 
-The rest should be custom variables... 

IIb - Now the Basics 
--------Where to start coding? Somewhere simple. Let's start with a simple zooming-in. It's simple, and easily substitutes Blitter Feedback. Don't forget that handy moving particle. 
-The code is simple, and short : d=d/1.01; 
-It's slow, but it's a start... want it to be faster? set it to a higher number! Note that 1.02 will make the zooming speed twice the current speed. Be careful, or you'll end up with... Something chaotic. 
-You can also substitute the code with d=d-0.01; It's quite a lot faster, and it unfortunately adds a bubbling effect to it. Use it when appropriate... We're talking about plain zooming right now. 
-Oh yeah, be sure leave bilinear filtering on and don't use "Clear Every Frame". 

--------Now that you zoomed in, let's zoom out! 
-The code is... d=d*1.01; 
-Not surprising, huh? It's simply the opposite of zooming in, so it just changes the division sign with the multiplication. 
-You can also change the code with the - sign into a code with a + sign. Zooms out, but with a side effect too. 
==Math behind it? Just read the formula, and remember, d is distance. 

--------So you've zoomed in and out... Now rotate. 
-R is rotation, so the code is simply r=r+0.05 or r=r-0.05; 
-"+" goes anti-clockwise, - goes clockwise 
-R doesn't cope well with "*" or "/". Don't use them. 
-Use with combination of D for a zooming and rotating movement. You can easily replace the "Tunneling" movement with combination of D and R, AND make newbies think you're a coder... Well, possibly. 

--------Move left, move right, move up, move down. 
-Now you'll learn simple x-y transition! Simplest thing in terms of math. 
-Check the "Rect Coords" checkbox. Sounds weird, but it needs to be used to make them transition work. 
-Simple X transition? x=x+0.01; or x=x-0.01; 
-Replace X with Y for Y transition. 
-Use combination of 2 at once for diagonal movement. 
-You can use x/y with d/r movement in conjunction, but that would take some advanced coding... Sorry, but you'll have to wait for a bit till you're able to do such thing, which seems like a simple thing, but definately isn't. 

III - Dynamics! 

IIIa - Simple dynamics 
--------Now, you get to play around with something more - The "Dynamic Movement". It's not named Dynamic for nothing. 
-First of all, change the grid size. What's your AVS window size? It should be "AxB", A and B being the size in pixles. The grid size should be A/10 and B/10. Do the math yourself. This is done to prevent the DM's tendency to move the image slightly to top-left. 
-The box you want to type in is the 3rd big box from the top, labeled "Pixel" or somwthing like that. 
-Try the basic movements that I told you in the previous chapter. It works the same as a typical movement! Good, eh? 
-One new variable : B. 1 on beat, 0 otherwise. 
-So, wanna dynamics? Try this : d=d/(1.01+b/10) 
-There! Now it got some nice beat-detection! 
-BTW, you can substitute a black OnBeat clear by using the code d=d+b. 
-Mess around with the number after B. It sets the speed. The higher, the less the change (You can even make it slow down! Use - for that.) 
-You can use R, X, or Y instead of D, too. 

IIIb - More dynamic! 
--------Now, you get to do the real deal. It changes every beat. Hopefully you got spare neurons ready. 
-Now you also get to tinker around with custom variables, and a function. 
-For this one, let's start with a rotation. it's quite short, too. 

On the first box (Init) : (none) 
On the second box (Frame) : (none) 
On the third box (beat) : t=rand(401)/1000-0.2; 
On the fourth box (pixel) : r=r+t; 

-Definition? It's quite as simple as r=r+0.01; but the "0.01" is replaced by a variable that changes its value every beat. So, one beat it can be 0.2, another 0.125, another -0.199, and even 0 in another one. 
-rand spits out a number which is in range of 0 to the number in the pharantheses... in this case, it goes from 0 to 400. 
-Rand is very random. It's linear-proof. 
-Remember to use a beat-ty song to see the difference! 

-------Now let's implement this to x/y movement! 
1st box : none 
2nd box : none 
3rd box : 
tx=rand(401)/1000-0.2; 
ty=rand(401)/1000-0.2; 
4th box : 
x=x+tx; 
y=y+ty; 

Check "Rect Coords" 

-Happy? You should probably be. Satisfied? Doubtful. 

IV - More coding... 
-------Getting to a bit more advanced stuff now. You're allowed to use typical trans/movement again now... 
-Let's do a "simple" one for now, shall we? 
-Code : d=d-cos(r*2)*0.01 
-Note the movement, it's not zooming in. It's not zooming out. Confused? Shouldn't be. 
-You can replace the number after the r with a lot of other numbers... it changes the number of "spouts" that exists. 
-The math? Just think of a cosine wave. You'll get it someday. 
-You can replace cos with sin. Only a location difference. 
-Want to rotate it around? use +# or -# (# being a number) after r*2, still inside the pharantheses. The good part is, now you get to use big numbers! 
-If you want to tilt it 90, use +acos(-1)/2. Remove the /2 for 180 rotation. Acos(-1) (Arccosine of -1) is very damn close to pi. in AVS, r is 2pi, so 2pi is 360 rotation. 
-Try d=d-abs(cos(r*2.5)*0.01) 

-------Let's move on to x and y again. 
-Code? Let's try to use cos again! 
-code : 
x=x+cos(y*10)*0.01; 
y=y+cos(x*10)*0.01; 
-Now you've made a swirly stuff! 
-Looks nice, and the number after x or y is the number of swirls. Play around. 

-------Now let's kick some movement presets outta the window. 
-Tunneling. Easy to duplicate! 
-Code? 
d=atan(d*1.01); 
r=r+0.05; 
-There! You've duplicated one of the preset movements! 

-Slight Fuzzily. Not exactly hard to duplicate... 
-Code, ye ask? 
x=x+(rand(126)/10000-0.00625); 
y=y+(rand(126)/10000-0.00625); 
-Don't forget to (For the first time ever) disable Bilinear Filtering and enable rect coords. 
-It's not complicated - Remember the rand function? Now we moved it into the Pixel part (The only part in movement, in this case), made it into a tiny movement, and subtracted by exactly half of it, so it scatters the image around every pixel.Different direction for each pixel too. 
-So you've downed another preset. Be happy. There's still one more, though. 

-Shift Rotate Left. very simple. 
-Code? 
x=x+0.03; 
Disable bilinear filtering, enable wrap. 
-That's it... 

-Big Swirl Out. Another simple one! 
-The code is... 
d=d/1.04; 
r=r+0.1*cos(d*3); 
(Don't forget to disable the rect coords. I won't bother to tell you to enable/disable it from now. You know how it works, don't you?) 
-The r function varies for each pixels' distance from the center one, behaving in a cosine-wave sort of way. 
-Another easy one down! Want another one? 

-Sunburster! It's quite popularly used among newbies (Ouch), and is not as easy to duplicate. 
-Code... 
d=d/(1+(cos(r*32)/25)+0.1); 
-Took me quite a bit longer to duplicate than other ones. 
-Yes, I know, it doesn't perfectly duplicate it *sigh* 
-Anyways, the number afta the r is the number of rays. 
-For 5-pointed Distro, use the following slightly-edited code : 
d=d/(1+(cos(r*5)/50)+0.05) 

-Swirling both ways at once. Long name, "short" code. 
-Code : 
r=r+sin(d*20)*0.1 
-I still have yet to fix the purely visible edge between each direction of swirl... But it's not THAT visible, right? 
-That was easy! 

-Sorry. That's all the preset movements you get to kick, folks! 

IIIc - Combining Boredom and Freedom 

------You've learned how to duplicate some preset movements, and they got boring quite quickly, does it? It's time to spice it up. 

------Tunneling : Remember the random-rotation DM? Use it here, plus these lines of codes : 

Beat : dt=rand(101)/1000; 
Pixel : d=atan(d/(1+dt)); 

-Remember, adding dynamics to movements may be as simple as making a number change each beat/slowly over each frame 

------Shift Rotate left... Just take random x/y movement, and omit the y part! 

-----Big swirl out... 
-It now undergoes a plastic surgery... looks so much better, and might even make you feel like a professional  
-Code : 
Beat : 
dt=rand(101)/1000; 
t=rand(201)/1000-0.1; 
ra=rand(11)+5; 
Pixel : 
d=d/(1+dt); 
r=r+t*cos(d*ra); 

-There! imagine that, 3 parts are randomized each beat - Zooming speed, rotation speed, and the "amount" of rotations. 

-----Sunburster 
-Only a change... Rotating the rays around doesn't give much difference on higher amount of rays. 
-Code : 
Beat : ra=rand(16)+10; 
Pixel : d=d/(1+(cos(r*ra)/25)+0.1); 

-The amount of rays is kept high so that the purpose of a sunburster is not gone. Unfortunately, it makes the change not very noticable too *sigh* 
-Change the beat part to "ra=rand(15)+1" if you're making dynamic 5-Pointed Distro. Feel free to add a good rotation too (t=t+t1 on frame and t1=rand(401)/1000-0.2 on beat)(Add inside the cosine function) 
-Enable the blend... I like it more that way =) 

-----Swirling Both Ways At Once 
-The amount of swirl now changes! I made it able to jiggle and wiggle too  

-Code : 
Frame : t=t+t1; 
Beat : 
ra=rand(15)+10; 
t1=rand(501)/1000-0.25; 
Pixel : r=r+sin(d*ra+t)*0.1 

-The amount of "ra" is kept high so that the swirling-both-ways is visible... Lower numbers don't seem to swirl both ways very well. 

-----Implementing your knowledge 
--What can you do with your newfound knowledge? 
-More tinkering. This time, you know a bit more of what you're doing. 
-Making kickass presets 
-Making your first pack to be presented to the world make people think you're going to be a good AVS artist   
-Giving yourself satisfaction 
-Not tearing your hair because not knowing coding. 

-Anyways... 

-----"Presets" that I Made 
--Preset DMs! Not intended to be used as the only thing you use. 

-"Shifting Flower Flow" (I'm not good at naming) 
Frame : 
t=t+t1; 
td=td+td1; 

Beat : 
ra=rand(14)+2; 
da=rand(14)+2; 
t1=rand(501)/1000-0.25; 
td1=rand(501)/1000-0.25; 

Pixel : 
r=r+sin(d*ra+t)*0.2; 
d=d+sin(r*da+td)*0.04; 

(Best when blend is on, offsetting the bad edges) 

-Whoops, did I say presetS? oh, whoops... 

IV : Morph the Image 

-----So you made a good lookin' preset... What's next? 
-----NOTE : Work with a good BG that also nicely display morphing for this part. Simply add a good and FAST preset for that. Interleave with the buttons 4 steps from left works nicely too. White color, clear every frame, of course. Change the color to non-white color (Or a bright one) and add Bump for... umm... boundary tracking. Make sure it's set to bumpiest. Oh, and recommended code for bump : 

Pixel : 

x=0.5+cos(tx)*0.3; 
y=0.5+sin(ty)*0.3; 
tx=tx+Tx1;ty=ty+Ty1; 

Beat : tx1=rand(501)*0.001-0.25;ty1=rand(501)*0.001-0.25; 

(It just makes it move randomly) 
(Oh, and setting the DM's grid size to w/10  h/10 is recommended... Since you can't punch in w and h, calculate yourself) 

-----Ready? Good! Type in "d=d*3" in the pixel section. 
-It makes a simple movement (It's in DM, but who cares?)... but it can be made using Roto Blitter. Without the painstaking pixel-perfect setting, that is. 

-----Fine, you want something un-Roto Blitter like. Note that this is quite a leap from the previous code... 

Frame : t=t+0.1 

Pixel : d=d/(1+cos(d*10-t)*0.2) 

-There! A nice ripple! 

Change pixel to : 

d=d/(y+(2+sin(y*10+t)*0.1)); 

And you get a Y-axis ripple with distance to the top. 

-----Dynamics? Why not! 

Frame : 

td=td+td1; 
tr=tr+tr1; 

Beat : 

dd=rand(10)+1; 
rr=rand(10)+1; 
td1=rand(501)*0.001-0.25; 
tr1=rand(501)*0.001-0.25; 

Pixel : 

d=d*(1+cos(d*dd+td)*0.1)*(1+sin(r*rr-tr)*0.1); 

Yes, a lot like that "preset" DM, but hey, translating 2d trailing movements to 3d depth (Distance translated in pixel = depth) have no guilt in it. 


IV(Continued)

-----So you've made a (very) nice DM... Why not go a little simpler and try a simple rotozoomer! 

-Code : 
Frame : td=td+td1;tr=tr+tr1; 
Beat : td1=rand(401)*0.001-0.2;tr1=rand(501)*0.001-0.25; 
Pixel : d=d*(2+sin(td));r=r+tr; 

Turn on wrap, of course! 

-So you made a rotozoomer... It's a classic effect! It doesn't quite replicate UnConeD's rotozoomer (On-Beat speed-ups, smooth rotation), but that can be done with more advanced coding. Not now, though. 

-----Since we don't want simple stuffs... 

-Code : 
Frame : tx=tx+tx1;ty=ty+ty1;t=t+t1; 
Beat : tx1=rand(501)*0.001-0.25;ty1=rand(501)*0.001-0.25; t1=rand(501)*0.001-0.25; 
Pixel : 
x1=x+sin(tx); 
y1=y+sin(ty); 
z=sin(x1*2)+cos(y1*2); 
x=x*sin(z+cos(z*(6+sin(t/2.5)*5))); 
y=y*cos(z+cos(z*(6+sin(t/2.5)*5))); 

Another bulge-here-bulge there? Try this with the my recommended setting, then disable the interleave. Oh, and cranking the grid size up to 50x50 helps, too. What you have now is an overly shiny thing. Shiny, moves around, morphs... Something people can stare for hours =) 
Why not use single D command, and use x and y? Using d makes an annoying trouble-area in the middle... we want good-looking preset... That troubled area is one ugly thing. We don't want ugly presets, do we! 

Ok, enough bulge this and bulge that. Time for something that's a bit less... bulgy. 

IVb - If Only I Master Coding... 

-----As in, "If" Commands. That command is not exactly easy to use, but is quite friendly once you know it. 

For starters, let's mirror! 

-Code : 

x=if(below(x,0),-x,x); 

-This is just like Trans - Mirror - Mirrored Right side to left side. 
-Switch around -x and x for different side (Or change Below with Above). 
-You can also replace x with y! Just make sure it's all x or y, or you'll get a serious distortion. 
-No, don't use d or r. 
-You can add the line of code at the very end of the DM to replace a Mirror. I don't know if it's less system-intensive than mirror or not, but it sure gives a more professional look (Look ma! no mirrors!) 
-Yes, you can use X and Y together. 
-"0" is the position. In X and Y, it runs from -1 to 1 (0 is the center). In D, it runs from 0 to 1. In R, it runs from 0 to 2*pi. 
-You can type in more coding after "-x" and "x". You can replace "-x" with "x" (So both sides have "x") and type in a whole coding in each space! Edited part of the left "x" will do its stuff on the left side. Same with other part. 
-In the pharantheses, you can change it between "x" and "y" to choose the "division" point. 
-When using "d" for the part left of "=", never mind about not doing it - Just make sure you don't use "d" or "r" as the division point. You can make one side zoom in and one side zoom out! Imagine the possibilities! Such thing will make peoples' head hurt though =) 

IVb - Continued 

-So, how do you make one of those odd effects? (Note : This is a trailing DM. Use multiple particles just for test) 

-Code : 

d=if(below(x,0),d/1.01,d*1.01); 

-There are many other possibilities... That's for you to figure out! 
-You can also get a bit crafty : 

-Code : 

x=if(below(x,0),x/1.01,x*1.01)*if(above(y,0),1.01,0.99); 
y=if(below(y,0),y*1.01,y/1.01)*if(above(x,0),1.01,0.99); 

-What about using the IF command on non-trailing DMs? 
-Say, what's a better place to start than a "Dance Hall" effect? 

-Code : 

FRAME : 

tx=tx+tx1; 
ty=ty+ty1; 

BEAT : 

tx1=rand(501)*0.001-0.25; 
ty1=rand(251)*0.001-0.125; 

PIXEL : 

x=x/if(below(y,-0.2),-y+0.5,if(above(y,0.2),y+0.5,0.7))+tx; 
y=y/if(below(y,-0.2),-y+0.5,if(above(y,0.2),y+0.5,0.7))+ty; 

-It's recommended that you remove "+ty" at the end of the Y line - It makes the Dance Hall effect too weird... 
-As you can see in the code, we're using If inside If. yes, you can do that! 
-This is a very simple form of a Dance Hall... The more complicated ones are definately more than 2 lines of code. 

V : SUPERscopes! 

Va - Introduction to "super"scopes 

-----What? Superscopes? (SSC for short) Yes, the stuff that anyone can resort to if you're daunted by DMs. Yes, it's the stuff that makes ugly-looking presets that much better (IF you use it right). 

-----Why Superscopes? It's useless to have kickass environment if the texture is crappy. Superscope can accomplish this task of creating good texture (when coupled with the right movements, of course). 

-----Superscopes are a lot similiar in terms of coding with DMs, but there ARE differences... 

-The variables x,y,v,i,w,h are the only preset variables. 
-No d, no r. You can use them as custom variables though... 
-...Or you can customize them to act a bit like d and r from DMs. That's a whole other story though... 
-You determine the location of points, it's a whole new game! 
-Two different points in different locations make a line if you choose to render in lines. 
-V is... Err... 
--Take out Render-Simple, put in oscillioscope mode. It gives the value of the height of the line (Think of it as a coordinate graph, 1/2 top is 1, 1/2 bottom is -1/2). V does the same thing, except that it's twice the height (It now reaches top and bottom of screen) 
--Make sure the selection you have near bottom is set to waveform, not spectrum to make this work. The Spectrum have a different way of numbering it. 

-i is... 
--i have a different value among each point, a bit like V. This one, however, is linear (Yes, that's a good thing), and also is perhaps the most useful variable below x,y, and n (It's not a default variable, but required. More on that later). 
--i goes from 0 to 1. The sequence is 0/n-1, 1/n-1, 2/n-1, ... , n-1/n-1. 
---n-1/n-1? The numerator is n-1 because the first number is 0, not 1. 
--So, what is it used for? Wait for a few moments. 
--What is "n"? it's next. 

-n is also an important variable. I didn't put it in the list for some odd reason... 
--It determines the amount of the points the SSC have. The more, the more detailed. 100-500 should do until you get to the advanced SSCs... 
--You should only need to define n in Init box until you get to advanced SSCs... 

-w is width of screen in pixels, h is the height in pixels. It won't be much use except for advanced uses (How many times have I said that?) 

-Enough talk, let's start! 

-----All superscopes (Well, hopefully) career starts with the simplest and most basic line of code... (Put in n=100 in the Init box first, you won't need to change it for a while) 

(Make sure you clean up the whole place first and set it to lines) 

-PIXEL : x=-1+i*2;y=0; 

--A line! It all starts here. A simple line. Of course, you'd want more! 

-PIXEL : x=-1+i*2;y=v/2; (Or y=v*0.5) 

--This one displays the music...just like Render-Simple! 
---More definition? 
---Here, x puts the dots from -1 (left side of screen) to 1 (right side of screen). i is multiplied by 2 to make it go all the way. This can be done with just 2 points, but those 100 points will be used later on. Sides, I want it to be convenient to you . y is the height of the dots, and it follows the same height as render-simple (halved because it goes with the REAL value!) 
--n=w will make as detailed of a Render/Simple as you can. 
--That, of course, shouldn't be enough to keep you satisfied. We always need more, do we! 

--Making a circle takes pi. You can always do pi=3.14whateverwhateverwhatever on Init, but there's a shorter way! 
---pi=acos(-1). A very indeginious equation (Yes, exagerated =P). It comes very close to pi! 
---22/7 works as well, but acos(-1) goes closer. I doubt you'll need it to go THAT detailed though, so it's ok to use it. 
---Now, put pi=acos(-1) on the Init section! 

-Circle! 
-PIXEL :x=sin(i*pi*2);y=cos(i*pi*2) 
--Why sin and cos? well, it's a long discussion and explanation... The whole explanation is available in Atero's AVS Primer. (Available at atero.deviantart.com [look at gallery]. You can also search for it, and you can even ask him personally for it [don't expect good reply, though...]. It also have explanations for WAAAAY many other things too! A must for beginners, I'd say...) (No, that wasn't sponsored by Atero) 
--If your window is not square, add /w*h at the end of the x line. Just simple resolution correction, don't worry  
--You want a spiral? add *i to the end of both lines of code (I know they're at the same line, but let's just refer x as line 1 and y as line 2. You might want to change the number (As in, the non-variable number) inside the sin and cos to make more rotations done in the spiral. Just make sure the sin and cos numbers are the same. If the 2 are different, it makes interesting things, I admit (Also happens when there's no *i, too!) 
--Circle... Not very exciting, isn't it? 

-PIXEL : 
x=sin(i*pi*2)*0.5+v*sin(i*pi*2)*0.25; 
y=cos(i*pi*2)*0.5+v*cos(i*pi*2)*0.25; 

-Aye, a music-detecting circle! The size is halved to show the whole thing better, and the v is quartered as a result first from halved for circle size, and halved for the usual halfing (hopefully you get what I mean). 
-If you want a resolution-correction, get the whole x (Just the part after = and before ;, of course) in a pharantheses, and apply the res-correction) 
-What? You don't care about music detection, and just want a cool stuff? 

-BEAT : tx1=rand(201)*0.001-0.1;ty1=rand(201)*0.001-0.1; (You can use /1000 instead of *0.001. *0.001 is slightly faster, and it became a habit for me) 
FRAME : tx=tx+tx1;ty=ty+ty1; (The variables can be anything, just like DMs, you should remember that. In fact, you can make the variable cusswords... but we AVS artists are civilized [Or at least I hope so], and it gets quite sore on the eyes when it comes to editing) 
PIXEL : x=sin(i*pi*2)*0.25+sin(tx)*0.75;y=cos(i*pi*2)*0.25+sin(tY)*0.75; 

--A circle that moves around! Yay! 
--Res-correction should be put before the +sin(tx). If you want the place the circle is kept in to be square to, apply pharantheses to the whole thing and do the res-correction. 
--To make it detect music too, add +v*sin(i*pi*2)*0.125 at the end of each line (Change sin to cos in y line) 
--The movement is reduced to keep the circle in screen. 
--If you had a spiral (refer to a previous section) and want it to rotate, you can add a random-on-beat number (Like tx-tx1 combo) and add it inside both sin and cosine. It doesn't do much in normal circles unless the number inside the sin and cosine are different. 

--Remember "If" from the last section of DMs? You can also use it here. Since you can't use big whole numbers, you'll either have to use decimals or the line p=n*i-i in pixel section (p=p+1 in pixel with p=0 in frame section will also do, and I think it's faster). After adding that line, what "p" will signify is the number 1 up to n, and the number is the number of the point! (As in, point #1, point #2, etc). This way, you can make several dots floating around, all in 1 SSC! If you use lines, it gets quite ugly, but there's where colorcoding comes in... 
